Skip to main content

Explain the concept of include and extends in consideration with use case scenario with example.

Β«IncludeΒ» and Β«ExtendΒ» Relationships in Use Case Diagrams​

In UML use case modeling, the Β«includeΒ» and Β«extendΒ» relationships are important concepts that help manage complexity and reduce redundancy in use case diagrams by showing how use cases relate to each other.

The Β«IncludeΒ» Relationship​

The Β«includeΒ» relationship indicates that a base use case explicitly incorporates the behavior of another use case at a specific location in its sequence. It represents mandatory behavior - the included use case will always be executed when the base use case is performed.

Key Characteristics of Β«IncludeΒ»:​

  1. Mandatory Execution: The included use case is always executed when the base use case runs
  2. Reuse of Functionality: Helps avoid duplication by extracting common behavior into separate use cases
  3. Simplification: Makes complex use cases more manageable by breaking them into smaller parts
  4. Direction: The arrow points from the base use case to the included use case
  5. Notation: Represented as a dashed arrow with the stereotype Β«includeΒ»

Example of Β«IncludeΒ» Relationship:​

In an online banking system:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Online Banking System β”‚
β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” Β«includeΒ» β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί β”‚ β”‚ β”‚
β”‚ β”‚ Transfer β”‚ β”‚ Verify β”‚ β”‚
β”‚ β”‚ Funds β”‚ β”‚ User β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” Β«includeΒ» β”‚
β”‚ β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ Pay Bills β”‚ β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β–Ό β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ Log β”‚ β”‚
β”‚ β”‚ Transactionβ”‚ β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

In this example:

  • Both "Transfer Funds" and "Pay Bills" include "Verify User" - User verification is a mandatory part of performing these operations
  • "Pay Bills" also includes "Log Transaction" - Transaction logging is always performed when paying bills

The Β«ExtendΒ» Relationship​

The Β«extendΒ» relationship indicates that a base use case may be augmented by another use case under specific conditions. It represents optional behavior that may or may not occur, depending on certain conditions.

Key Characteristics of Β«ExtendΒ»:​

  1. Conditional Execution: The extending use case is only executed if specific conditions are met
  2. Optional Behavior: Represents behavior that may not always occur
  3. Extension Points: Defines where in the base use case the extension may be inserted
  4. Direction: The arrow points from the extending use case to the base use case
  5. Notation: Represented as a dashed arrow with the stereotype Β«extendΒ»

Example of Β«ExtendΒ» Relationship:​

In an e-commerce system:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ E-Commerce System β”‚
β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ β”‚ Β«extendΒ» β”‚ β”‚ β”‚
β”‚ β”‚ Checkout │◄────────────────── Apply Discount β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ Extension points: β”‚ β”‚ β”‚
β”‚ β”‚ - Calculate total β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚
β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ β”‚ Β«extendΒ» β”‚ β”‚ β”‚
β”‚ β”‚ Process │◄────────────────── Verify Credit β”‚ β”‚
β”‚ β”‚ Payment β”‚ β”‚ Card β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ Extension points: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”‚ - Payment method β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

In this example:

  • "Apply Discount" extends "Checkout" - Discounts are only applied if the customer has a valid discount code
  • "Verify Credit Card" extends "Process Payment" - Credit card verification only occurs if the customer chooses to pay by credit card

Comparing Β«IncludeΒ» and Β«ExtendΒ» Relationships​

Aspect«Include»«Extend»
NatureMandatory behaviorOptional behavior
DirectionBase use case β†’ included use caseExtending use case β†’ base use case
PurposeReuse common functionalityAdd optional behavior
ExecutionAlways executedExecuted only if conditions are met
ControlBase use case controls when included use case executesBase use case may be unaware of extension
UsageExtract common functionalityHandle alternative flows and exceptions

When to Use Each Relationship​

Use Β«IncludeΒ» when:​

  • The same functionality appears in multiple use cases
  • A complex use case needs to be broken down into more manageable parts
  • You want to explicitly show that a certain functionality is always performed

Use Β«ExtendΒ» when:​

  • Behavior is optional and occurs only under certain conditions
  • You want to separate exceptional or alternative flows from the main use case
  • Additional functionality might be added to a use case without modifying it

Both relationships help in creating more modular, maintainable use case models that accurately represent the behavior of complex systems while remaining understandable to stakeholders.